import { CurrentUser } from '@/decorators';
import { GiftCommandDto } from '@/dtos';
import { GiftService } from '@/services/gift.service';
import { ok } from '@/utils';
import { Body, Controller, Post } from '@nestjs/common';
import { Throttle, seconds } from '@nestjs/throttler';
import { BaseController } from './base.controller';

@Controller('gift')
export class GiftController extends BaseController {
  constructor(private readonly giftService: GiftService) {
    super();
  }

  @Post('command')
  @Throttle({
    short: {
      ttl: seconds(1),
      limit: 1,
    },
  })
  async command(@Body() dto: GiftCommandDto, @CurrentUser('id') id: number) {
    return ok(await this.giftService.command(dto, id));
  }
}
